package cn.kshost.zqyg.common.service.config;

import cn.kshost.zqyg.common.service.interceptor.UserLoginAuthInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class MvcConfig implements WebMvcConfigurer {

    @Autowired
      UserLoginAuthInterceptor userLoginAuthInterceptor;
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**") //允许路径
                .allowedOriginPatterns("*") //允许所有源地址
                .allowedMethods("*") //允许所有
                .allowedHeaders("*") //允许所有请求头
                .allowCredentials(true); //允许携带token
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(userLoginAuthInterceptor).addPathPatterns("/api/**/auth/**");
    }
}
